import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { Logger } from './shared/logger/logger.service';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  //全局日志
  app.useLogger(app.get(Logger));

  // 全局管道
  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      forbidNonWhitelisted: true,
      transform: true,
    }),
  );

  // 捕获未处理的 Promise 拒绝
  process.on('unhandledRejection', (reason, promise) => {
    console.error('Unhandled Rejection at:', promise, 'reason:', reason);
  });

  // app.setGlobalPrefix('api');

  await app.listen(8866);
  console.log('current environment: ', process.env.NODE_ENV);
  console.log('mysql host: ', process.env.DATABASE_HOST);
  console.log('Test API: http://localhost:8866');
}
bootstrap();
